<!DOCTYPE html>
<html lang="en">
<head>
	<meta charset="UTF-8">
	<meta name="viewport" content="width=device-width, user-scalable=no, initial-scale=1.0, maximum-scale=1.0, minimum-scale=1.0">
	<title>报表</title>
	<meta name ="description" content="弹窗">
	<link href="/layui/css/layui.css" rel="stylesheet"/>
	<style>
		.layui-form{
			padding-top:15px;
			padding-right: 15px;
		}
		.flow-default{width: 100%; overflow: auto; font-size: 0;}
		.flow-default li{
			display: inline-block;
			margin: 0 5px;
			font-size: 14px;
			width: 19%;
			margin-bottom: 10px;
			height: 100px;
			text-align: center;
			background-color: #eee;
			padding-top:25px;
			-webkit-box-sizing: border-box;
			-moz-box-sizing: border-box;
			box-sizing: border-box;
		}
		.flow-default i{
			display: block;
			font-style: normal;
			margin-top:10px;
		}
		.layui-form-label{
			width: auto;
		}
	</style>
</head>
<body style="width: 80%;margin: 0 auto;">
<span style="float: left;margin-top: 10px;">欢迎你，<a href="#" style="color: cadetblue"><?php echo $username;?></a></span>
<a href="/report/logout" style="float: right;margin-top: 10px;color:cadetblue">退出登录</a>
<hr />
<ul class="layui-nav">
	<li class="layui-nav-item"><a href="/report/data">总览</a></li>
	<?php if ($username == 'admin') : ?>
		<li class="layui-nav-item"><a href="/report/index">数据列表</a></li>
	<?php endif;?>
</ul>
<form class="layui-form">
	<div class="layui-form-item" style="margin-top: 15px;">
	<?php if (isset($sonSource) && !empty($sonSource)) : ?>
		<label class="layui-form-label">请选择渠道</label>
		<div class="layui-input-inline" >
			<select name="s_id" id="sources" >
				<option value="0">可选择</option>
				<?php foreach ($sonSource as $key =>$value) : ?>
					<option value="<?php echo $value->id;  ?>" <?php if(isset($s_id) && $value->id==$s_id): ?>selected<?php endif; ?> ><?php echo  $value->name;  ?></option>
				<?php endforeach; ?>
			</select>
		</div>
	<?php else : ?>
		<label class="layui-form-label">请选择渠道</label>
		<div class="layui-input-inline">
			<select name="p_id" id="parent_source" lay-filter="parent_source">
				<option value="0">可选择</option>
				<?php foreach ($parentSource as $key =>$value) : ?>
					<option value="<?php echo $value->id;  ?>" <?php if(isset($p_id) && $value->id==$p_id): ?>selected<?php endif; ?> ><?php echo  $value->name;  ?></option>
				<?php endforeach; ?>
			</select>
		</div>
		<div class="layui-input-inline" >
			<select name="s_id" id="sources" >
				<option value="0">可选择</option>
				<?php foreach ($slist as $key =>$value) : ?>
					<option value="<?php echo $value->id;  ?>" <?php if(isset($s_id) && $value->id==$s_id): ?>selected<?php endif; ?> ><?php echo  $value->name;  ?></option>
				<?php endforeach; ?>
			</select>
		</div>
	<?php endif;?>
		<div class="layui-inline">
			<label class="layui-form-label">选择日期</label>
			<div class="layui-input-inline">
				<input type="text" name="start" id="start"  placeholder="" autocomplete="off" class="layui-input" onclick="layui.laydate({elem: this})">
			</div>
			<div class="layui-input-inline">
				<input type="text" name="end" id="end"  placeholder="" autocomplete="off" class="layui-input" onclick="layui.laydate({elem: this})">
			</div>
			<div class="layui-input-inline">
				<button type="submit" class="layui-btn" lay-submit lay-filter="demo1">查询</button>
			</div>
		</div>
	</div>
	<div id="ulDiv" style="display: none">
		<label class="layui-form-label" id="searchTitle">查询结果</label>
		<ul class="flow-default">
			<li><span>累计新增</span><i id="searchEnd"></i></li>
		</ul>
	</div>
	<label class="layui-form-label">数据看板</label>
	<ul class="flow-default" id="LAY_demo1">
		<li><span>今日新增</span><i><?php echo $jr;?></i></li>
		<li><span>昨日新增</span><i><?php echo $zr;?></i></li>
		<li><span>本周新增</span><i><?php echo $bz;?></i></li>
		<li><span>本月新增</span><i><?php echo $by;?></i></li>
		<li><span>累计新增</span><i><?php echo $lj;?></i></li>
	</ul>

</form>
<script src="/assets/js/building/jquery-1.11.1.min.js"></script>
<script src="/layui/lay/dest/layui.all.js"></script>
<script src='/assets/js/codeigniter-csrf.js'></script>
<script>
	layui.use(['form', 'layedit', 'laydate'], function(){

	});
	var form = layui.form();
	form.on('select(parent_source)', function(data){
		console.log(data.value);
		if (data.value > 0) {
			$.ajax({
				method: "GET",
				url: "/report/ajax_source_data",
				data: {p_id:data.value}
			}).done(function(data){
				console.log(data);
				$("#sources").html(data);
				form.render('select');
			})
		} else {
			$("#sources").html('<option selected="selected" value="0">可选择</option>');
		}
	});

	form.on('submit(demo1)', function(data){

		var start = data.field.start;
		var end = data.field.end;
		var s_id = data.field.s_id;
		var p_id = data.field.p_id;
		if(start == "" && end == "" && s_id == '0' && p_id== '0' ){
			layer.msg("查询条件不可全为空", {
				time: 1000, //1s后自动关闭
			});
			return false;
		}
		if(start != ""){
			if(end == ""){
				layer.msg("截止日期不能为空", {
					time: 1000, //1s后自动关闭
				});
				return false;
			}
		}
		if(end != ""){
			if(start == ""){
				layer.msg("开始日期不能为空", {
					time: 1000, //1s后自动关闭
				});
				return false;
			}
		}
		var URL="/report/getDataByDate";
		$.ajax({
			type: "POST",
			url: URL,
			dataType:'json',
			data: {
				'start':start,
				'end':end,
				'p_id':p_id,
				's_id':s_id,
				'ci_csrf_token': ci_csrf_token()
			},
			success: function(msg){
				console.log(msg.num);
				$("#searchEnd").html(msg.num);
				$("#searchTitle").html("查询结果");
				$("#ulDiv").show();
			}
		});
		return false;
	});
</script>
</body>
</html>